﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoPlayerMissions : SignedApiCall
    {
        public IEnumerable<ApiMission> Missions { get; private set; }

        public ApiInfoPlayerMissions()
        {
        }

        public ApiInfoPlayerMissions(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int playerId, int days)
        {
            LoadSignedApiCall(string.Format("playerId={0}&days={1}", playerId, days));

            XmlNodeList missionNodes = XmlDocument.GetElementsByTagName("a:get_player_missionsResult");
            List<ApiMission> missions = new List<ApiMission>();
            foreach (XmlNode missionNode in missionNodes)
            {
                missions.Add(new ApiMission(missionNode.CreateNavigator().ReadSubtree()));
            }
            Missions = missions;
        }

        protected override string ApiCallName
        {
            get { return "PlayerMissions"; }
        }

    }
}
